<template>
    <div class="h_box">
      <titleTop :titleTxet="titleTxet"></titleTop>
      <div class="s_box">
        <p>
          <span>已参与的活动</span>
          <span @click="party()">查看更多 <img src="../../../assets/img/youjian.png" alt=""></span>
        </p>
        <ul class="ultwo">
          <li @click="actdet(item)" v-for="(item,index) in dataty" :key="index">
            <div class="li-top">
              <img :src="item.main_pic" alt="">
              <span>{{item.apply}}</span>
              <span v-if="item.is_rec==0?false:true">推荐</span>
            </div>
            <p>{{item.title}}</p>
          </li>
        </ul>
      </div>

      <p class="dop">活动动态</p>
      <ul class="ja_ul">
        <li v-for="(item,index) in acData" :key="index">
          <div class="left">
            <img :src="item.avatar" alt="">
          </div>
          <div class="right">
            <p>{{item.user_login}}</p>
            <div @click="Adetail(item)" class="zheng">
              <p>{{item.content}}</p>
              <div class="img" v-show="item.image.length==0?false:true">
                <img :class="item.image.length>1?'actimg':''" v-for="(item2,index2) in item.image" :src="item2" alt="" :key="index2">
              </div>
            </div>
            <div class="r_foot">
              <span>{{item.create_time | simplyToRelativeTime}}</span>
              <div class="r_right">
                <img @click="like3(item)" :src="item.status==1?'./static/lyl/like.png':'./static/lyl/like2.png'" alt="">
                <img @click="ping2(item)" src="../../../assets/img/ping.png" alt="">
              </div>
            </div>
          </div>
        </li>
      </ul>

      <div class="m_footer">
        <span @click="activity()">发起活动</span>
        <span @click="dynac()">发布动态</span>
      </div>

      <transition name="van-slide-right">
        <div v-show="visible" class="tran_right">{{Fade}}</div>
      </transition>
    </div>
</template>

<script>
  import {Dialog} from 'vant';
  import titleTop from "../../com/title";
  import * as search from "../../../api/search.js"
  import * as home from "../../../api/home.js";
  import * as list from "../../../api/list.js";
    export default {
      name: "HouDong",
      components: { titleTop },
      data() {
        return {
          titleTxet: {
            titleName: "活动管理",
            IsBool: true,
            IsShare: false
          },
          Fade:'',
          visible:false,
          dataty:[],
          acData:[]
        }
      },
      beforeMount(){

        let parms = {num:1,user_id:this.$store.state.user_id}
        search.myActive(parms).then(res=>{
          console.log('参与的活动',res)
          this.dataty = res.data;
          //参与活动动态
          let parms2 = {user_id:this.$store.state.user_id,id:res.data[0].id,type:1}
          list.activeDynamic(parms2).then(res=>{
            console.log('参与活动动态',res)
            this.acData = res.data;
          })
        })

      },
      methods:{
        actdet(item){
          this.$router.push({path:'/active2/0/'+item.id});
        },
        party(){
          this.$router.push("/gengduohuo")
        },
        Adetail(item){
          this.$router.push({
            path:'/acticont',
            query:{
              id:item.id,
              uid:item.uid
            }
          })
        },
        dynac(){
          this.$router.push("/myPublishDynamic")
        },
        ping2(item){
          this.$router.push({
            path:'/acticont',
            query:{
              id:item.id,
              uid:item.uid,
              bol:true
            }
          })
        },
        like3(itl){
          if (itl.status==1){
            itl.status=0;
            let parms = {
              id:itl.id,
              user_id:this.$store.state.user_id,
              status:itl.status
            };
            list.activeDynamicLike(parms).then(res=>{
              console.log(res);
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            })
          } else{
            itl.status=1;
            let parms = {
              id:itl.id,
              user_id:this.$store.state.user_id,
              status:itl.status
            };
            list.activeDynamicLike(parms).then(res=>{
              console.log(res);
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            })
          }
        },
        activity(){
          if (this.$store.state.user_id.length==0) {
            this.$router.push('/register')
          }else{
            let parms = {user_id:this.$store.state.user_id};
            list.isAuth(parms).then(res=>{
              if (res.data.is_auth==0){
                Dialog.confirm({
                  title:'你还没认证，不能发起活动',
                  message: "是否前往认证？"
                }).then(()=>{
                  this.$router.push('/myRealRadio');
                });
              } else{
                this.$router.push('/activity');
              }
            });
          }
        }
      },
      filters:{
        simplyToRelativeTime(timestamp) {
          let currentUnixTime = Math.round((new Date()).getTime() / 1000);       // 当前时间的秒数
          let deltaSecond = currentUnixTime - parseInt(timestamp, 10);            // 当前时间与要转换的时间差（ s ）
          let result;

          if (deltaSecond < 60) {
            result = deltaSecond + '秒前';
          } else if (deltaSecond < 3600) {
            result = Math.floor(deltaSecond / 60) + '分钟前';
          } else if (deltaSecond < 86400) {
            result = Math.floor(deltaSecond / 3600) + '小时前';
          } else {
            result = Math.floor(deltaSecond / 86400) + '天前';
          }
          return result;
        }
      }
    }
</script>

<style scoped>
  .h_box{
    padding-bottom: 90px;
  }
  .s_box>p:nth-child(1){
    font-size: 32px;
    padding:20px 40px 0;
    display: flex;
    justify-content: space-between;
  }
  .s_box>p:nth-child(1) span:nth-child(2){
    align-self: center;
    font-size: 24px;
  }
  .s_box>p:nth-child(1) img{
    height: 20px;
  }
  .ultwo{
    padding: 20px 40px;
  }
  .ultwo li{
    position: relative;
    border-radius: 20px;
    background: #e7c7fd;
    overflow: hidden;
  }
  .ultwo li .li-top{
    position: relative;
    height: 400px;
    overflow: hidden;
  }
  .ultwo li .li-top img{
    width: 100%;
    height: 100%;
  }
  .ultwo li .li-top span{
    position: absolute;
    left: 20px;
    top: 20px;
    display: inline-block;
    cursor: pointer;
  }
  .ultwo li .li-top span:nth-child(2){
    position: absolute;
    right: 20px;
    top: 20px;
    width: 90px;
    height: 40px;
    border-radius: 20px;
    text-align: center;
    line-height: 40px;
    background: #ff6174;
    color: #fff;
  }
  .ultwo li .li-top span:nth-child(3){
    width: 52px;
    height: 63px;
    background: url("/static/lyl/recom.png") no-repeat center/cover;
    font-size: 24px;
    color: #fff;
    float: right;
    text-align: center;
  }
  .ultwo li p{
    position: absolute;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    width: 100%;
    font-size: 24px;
    color: #fff;
    padding: 13px 0 10px 20px;
    background: rgba(0,0,0,0.7);
  }

  .dop{
    padding: 20px 40px;
    font-size: 32px;
  }
  .ja_ul li{
    padding: 20px 40px;
    display: flex;
    border-bottom: 2px solid #dcdcdc;
  }
  .ja_ul li .left img{
    width: 90px;
    height: 90px;
    border-radius: 50%;
  }
  .ja_ul li .right{
    flex-grow: 1;
    padding-left: 15px;
  }
  .ja_ul li .right>p{
    font-size: 36px;
    color: #884ca4;
    padding-bottom: 20px;
  }
  .ja_ul li .right .zheng p{
    font-size: 20px;
    padding-bottom: 20px;
  }
  .ja_ul li .right .img img{
    width: 350px;
    height: 500px;
  }
  .ja_ul li .right .img .actimg{
    width: 180px;
    height: 180px;
    margin:0 10px 10px 0;
  }
  .ja_ul li .right .img img:nth-child(3n+3){
    margin-right: 0;
  }
  .ja_ul li .right .r_foot{
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
  }
  .ja_ul li .right .r_foot span{
    font-size: 18px;
    color: #818181;
  }
  .ja_ul li .right .r_foot .r_right img:nth-child(1){
    width: 35px;
    height: 35px;
    margin-right: 20px;
  }
  .ja_ul li .right .r_foot .r_right img:nth-child(2){
    width: 40px;
    height: 35px;
  }

  .m_footer{
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 90px;
    display: flex;
  }
  .m_footer span{
    font-size: 32px;
    background: #d8d8d8;
    width: 50%;
    height: 100%;
    line-height: 80px;
    text-align: center;
    border: 2px solid #dcdcdc;
  }
  .m_footer span:nth-child(2){
    background: #cbcbcc;
  }
  .tran_right{
    width: 220px;
    height: 60px;
    border-radius: 10px;
    text-align: center;
    line-height: 60px;
    font-size: 30px;
    top: 50%;
    left: 50%;
    position: fixed;
    background: rgba(0,0,0,0.6);
    color: #fff;
  }
</style>
